﻿using AutoMapper;
using MediatR;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Traceability.App.Api.Read.Application.Command.FramCompany;
using Traceability.App.Domain;
using Traceability.App.Domain.养殖基本信息表;
using Traceability.App.ErrorCode;
using Traceability.App.Intrastructure.Interface;

namespace Traceability.App.Api.Read.Application.Handler.FramCompany
{
    public class GetComangHandler : IRequestHandler<GetComangCommand, ApiResult<FarmCompanyModel>>
    {
        private readonly IBaseRepository<FarmCompanyModel> farmcomanyRepo;
        private readonly IMapper mapper;

        public GetComangHandler(IBaseRepository<FarmCompanyModel> farmcomanyRepo, IMapper mapper)
        {
            this.farmcomanyRepo = farmcomanyRepo;
            this.mapper = mapper;
        }
        public Task<ApiResult<FarmCompanyModel>> Handle(GetComangCommand request, CancellationToken cancellationToken)
        {
            var res = new ApiResult<FarmCompanyModel>();
            var m = farmcomanyRepo.GetAll().Where(x => x.ProduceBatch == request.ProduceBatch).FirstOrDefault();
            res.Message = "养殖显示成功";
            res.Code = ApiEnum.Ok;
            res.Data = m;
            return Task.FromResult(res);
        }
    }
}
